﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models;
using BLL;
namespace CMS项目.Areas.HouTaiArea.Controllers
{
    public class CMS_CategoryController : Controller
    {
        // GET: HouTaiArea/CMS_Category
        BLLCMS_Category BLLCMS_Category = new BLLCMS_Category();
        public ActionResult CMS_Category()
        {
            return View(BLLCMS_Category.seleAll_CMS_Category());
        }

        [HttpGet]
        // GET: HouTaiArea/Category
        public ActionResult Add()
        {
            return View();
        }
        //添加
        [HttpPost]
        public ActionResult Add(CMS_Category Category)
        {
            int st = BLLCMS_Category.Insert(Category);
            if (st > 0)
            {
                return Content("<script>alert('保存成功');window.location.href='/HouTaiArea/CMS_Category/index';</script>");
            }
            else
            {
                return Content("<script>alert('保存失败');window.location.href='/HouTaiArea/CMS_Category/Index';</script>");
            }


        }
        //删除
        public ActionResult Delete(int id)
        {
            int st = BLLCMS_Category.Datete(id);

            if (st > 0)
            {
                return Content("<script>alert('删除成功');window.location.href='/HouTaiArea/CMS_Category/index';</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');window.location.href='/HouTaiArea/CMS_Category/Index';</script>");
            }

        }
        //单值查询
        public ActionResult Update(int id)
        {
            List<CMS_Category> li = BLLCMS_Category.Selectid(id);
            return View(li);
        }
        //修改
        public ActionResult Update_Category(int cid, string ctitle, string cname, bool nav, int navorder, bool search)
        {
            int st = BLLCMS_Category.update_CMS_Category(cid, ctitle, cname, nav, navorder, search);
            if (st > 0)
            {
                return Content("<script>alert('修改成功');window.location.href='/HouTaiArea/CMS_Category/index';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');window.location.href='/HouTaiArea/CMS_Category/Index';</script>");
            }
        }
        public ActionResult index()
        {
            return View();

        }
        //分页
        [HttpGet]
        public ActionResult SelectPage(int? pageindex, int? pagesize)
        {
            return Json(BLLCMS_Category.GetPageCMS_Articles((int)pageindex, (int)pagesize, null), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult SelectPage(int? pageindex, int? pagesize, string cid)
        {
            return Json(BLLCMS_Category.GetPageCMS_Articles((int)pageindex, (int)pagesize, cid));
        }
    }
}